<?php

    session_start();
    class datcom extends CI_Controller{
        public $mahoso=0;
    function __construct(){
        
        parent::__construct();
        $this->load->helper('url');
        $this->load->library(array('form_validation','session'));
        $this->load->library('userlayout');
        $this->userlayout->setLayout("user/layout");
        
        $userSession = $this->session->userdata('user');
        if($userSession['username'] == false){
            redirect(base_url('/index/login?returnUrl=').urlencode(RETURN_URL)); 
        }
        $this->mahoso = $userSession['MaHoSo'];
    }
    
        
        function index(){
            $this->load->model("user/datcom_model");
            $result = $this->datcom_model->getListNgayDatCom();
            $resultDaDat = $this->datcom_model->getListNgayDaDat($this->mahoso);
            
            $temp_arr = array();
            $temp_arr['result'] = $result;
            $temp_arr['resultDaDat'] = $resultDaDat;
//            $temp_arr['num_row']=$this->datcom_model->num_row();
            $temp_arr['title'] = "Danh sách ngày đặt cơm";
            $temp_arr['mahoso']=2;
            $title = "Đặt cơm";
            $currTemp = array('&nbsp;&nbsp; Đặt cơm');
            $current['current'] = $currTemp;
            $this->userlayout->view("user/datcom_view",$temp_arr,$title, $current );
            
        }
        
        function submitDatCom() {
            $this->load->model("user/datcom_model");
            
            for ($i = 0; $i < count($_POST["checkbox"]); $i++) {
                if ($_POST["checkbox"][$i] != "") {
                    $this->datcom_model->insertDatCom($_POST["checkbox"][$i],$this->mahoso);
                } 
            }  
        redirect('/nhanvien/datcom');
        }
        
        function  deleteDatCom() {
            $this->load->model("user/datcom_model"); 
            for ($i = 0; $i < count($_POST["checkboxxoa"]); $i++) {
                if ($_POST["checkboxxoa"][$i] != "") {
                    $this->datcom_model->deleteDatCom($_POST["checkboxxoa"][$i],$this->mahoso); 
                } 
//                else{
//                    $this->datcom_model->deleteDatCom($_POST["checkbox"][$i],2);
//                }
            }  
//            $result = $this->datcom_model->insertDatCom(1,2);
        redirect('/nhanvien/datcom');
        }
    }
?>